package com.caimiao.miao.page.master.storage.enter;

import android.content.Context;
import android.text.TextUtils;

import com.caimiao.miao.R;
import com.caimiao.miao.adapter.SimpleSpinnerAdapter;
import com.caimiao.miao.interfaces.BasePresenterImpl;
import com.caimiao.miao.library.utils.tip.ToastUtil;

public class EnterPresenter extends BasePresenterImpl<IEnterContact.View, IEnterContact.Model> implements IEnterContact.Presenter {

    public EnterPresenter(IEnterContact.View mView) {
        super(mView);
    }

    @Override
    protected IEnterContact.Model getModel() {
        return new EnterModel();
    }

    @Override
    public void start(Context context) {
        mView.setAdapter(new SimpleSpinnerAdapter(context, mModel.getType(context)));
    }

    @Override
    public void save(Context context, String type, int count) {
        if (TextUtils.isEmpty(type)) {
            ToastUtil.show(R.string.toast_storage_type);
        } else if (count <= 0) {
            ToastUtil.show(R.string.toast_storage_count);
        } else {
            mModel.save(context, type, count);
            if (mBinder != null)
                mBinder.getService().postAddTicket();
            mView.close(null);
        }
    }
}
